/*
 * Created by JFormDesigner on Sun Jun 30 00:14:39 CST 2024
 */

package scct.hys.ui;

import scct.hys.dao.MovieDao;

import java.awt.*;
import java.awt.event.*;
import java.sql.SQLOutput;
import javax.swing.*;

/**
 * @author 26984
 */
public class DlgMovieAdd extends JDialog {
    int id;
    public DlgMovieAdd(Window owner) {

        super(owner);
        this.id=id;
        initComponents();

    }

    private void btnAdd(ActionEvent e) {
        // TODO add your code here
    String name=txtActorName.getText();
    String director=txtDirectorName.getText();
    String actor=txtActorName.getText();
    String releasedata= txtReleasedata.getText();
    String duration=txtDuration.getText();

    MovieDao movieDao=new MovieDao();
        if (movieDao.addMovie(name,director,actor,releasedata, duration)){
        JOptionPane.showMessageDialog(this,"添加成功");
    }
    this.dispose();
        System.out.println(actor);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 韩月生
        label1 = new JLabel();
        txtMovieName = new JTextField();
        label2 = new JLabel();
        txtDirectorName = new JTextField();
        label3 = new JLabel();
        txtActorName = new JTextField();
        label4 = new JLabel();
        txtReleasedata = new JTextField();
        label5 = new JLabel();
        scrollPane1 = new JScrollPane();
        txtDuration = new JTextArea();
        btnAdd = new JButton();
        btnCancel = new JButton();

        //======== this ========
        setTitle("\u5f71\u7247\u6dfb\u52a0");
        var contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u5f71\u7247\u540d\u79f0");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(25, 40), label1.getPreferredSize()));
        contentPane.add(txtMovieName);
        txtMovieName.setBounds(105, 35, 100, txtMovieName.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u5bfc\u6f14\u59d3\u540d");
        contentPane.add(label2);
        label2.setBounds(25, 80, label2.getPreferredSize().width, 17);
        contentPane.add(txtDirectorName);
        txtDirectorName.setBounds(105, 70, 100, txtDirectorName.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u4e3b\u6f14\u59d3\u540d");
        contentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(225, 80), label3.getPreferredSize()));
        contentPane.add(txtActorName);
        txtActorName.setBounds(290, 75, 100, txtActorName.getPreferredSize().height);

        //---- label4 ----
        label4.setText("\u4e0a\u6620\u65f6\u957f");
        contentPane.add(label4);
        label4.setBounds(25, 120, label4.getPreferredSize().width, 17);
        contentPane.add(txtReleasedata);
        txtReleasedata.setBounds(105, 115, 100, txtReleasedata.getPreferredSize().height);

        //---- label5 ----
        label5.setText("\u7535\u5f71\u8bc4\u4ef7");
        contentPane.add(label5);
        label5.setBounds(new Rectangle(new Point(25, 155), label5.getPreferredSize()));

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(txtDuration);
        }
        contentPane.add(scrollPane1);
        scrollPane1.setBounds(105, 155, 285, 45);

        //---- btnAdd ----
        btnAdd.setText("\u6dfb\u52a0");
        btnAdd.addActionListener(e -> btnAdd(e));
        contentPane.add(btnAdd);
        btnAdd.setBounds(55, 225, 95, 30);

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        contentPane.add(btnCancel);
        btnCancel.setBounds(260, 225, 95, 30);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(445, 320);
        setLocationRelativeTo(null);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 韩月生
    private JLabel label1;
    private JTextField txtMovieName;
    private JLabel label2;
    private JTextField txtDirectorName;
    private JLabel label3;
    private JTextField txtActorName;
    private JLabel label4;
    private JTextField txtReleasedata;
    private JLabel label5;
    private JScrollPane scrollPane1;
    private JTextArea txtDuration;
    private JButton btnAdd;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
